package org.irri.smta.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "SMTA_REPORT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SmtaReport extends TimestampedAutoIdEntity implements
		Comparable<SmtaReport> {

	private static final long serialVersionUID = 1L;

	private static final int SYMBOL_LENGTH = 128;
	private static final int SMTA_DATE_LENGTH = 10;
	private static final int SMTA_TYPE_LENGTH = 2;
	private static final int LANGUAGE_LENGTH = 2;
	private static final int PROVIDER_TYPE_LENGTH = 2;
	private static final int PROVIDER_PID_LENGTH = 6;
	private static final int PROVIDER_NAME_LENGTH = 128;
	private static final int PROVIDER_ADDRESS_LENGTH = 65536;
	private static final int PROVIDER_COUNTRY_LENGTH = 3;
	private static final int PROVIDER_EMAIL_LENGTH = 128;
	private static final int RECIPIENT_TYPE_LENGTH = 2;
	private static final int RECIPIENT_PID_LENGTH = 6;
	private static final int RECIPIENT_NAME_LENGTH = 128;
	private static final int RECIPIENT_ADDRESS_LENGTH = 65536;
	private static final int RECIPIENT_COUNTRY_LENGTH = 3;
	private static final int SHIPMENT_NAME_LENGTH = 256;
	private static final int DOCUMENT_LOCATION_LENGTH = 1;
	private static final int DOCUMENT_RETRIEVAL_INFO_LENGTH = 128;
	private static final int PDF_URL_LENGTH = 2000;
	private static final int IRRI_AUTHORIZED_OFFICIAL_NAME_LENGTH = 256;
	private static final int IRRI_AUTHORIZED_OFFICIAL_DETAILS_LENGTH = 2000;
	private static final int RECIPIENT_AUTHORIZED_OFFICIAL_NAME_LENGTH = 256;
	private static final int RECIPIENT_AUTHORIZED_OFFICIAL_DETAILS_LENGTH = 2000;
	private static final int RECIPIENT_INDIVIDUAL_NAME_LENGTH = 256;
	private static final int RECIPIENT_INDIVIDUAL_DETAILS_LENGTH = 2000;
	private static final int RECIPIENT_ORGANIZATION_NAME_LENGTH = 256;
	private static final int RECIPIENT_ORGANIZATION_DETAILS_LENGTH = 2000;
	private static final int PROV_AO_NAME_LENGTH = 256;
	private static final int PROV_AO_TITLE_LENGTH = 256;
	private static final int PROV_AO_EMAIL_LENGTH = 128;
	private static final int PROV_AO_PHONE_LENGTH = 30;
	private static final int PROV_AO_FAX_LENGTH = 30;
	private static final int SENDER_NAME_LENGTH = 256;
	private static final int SENDER_TITLE_LENGTH = 256;
	private static final int RECIP_AO_NAME_LENGTH = 256;
	private static final int RECIP_AO_TITLE_LENGTH = 256;
	private static final int RECIP_AO_EMAIL_LENGTH = 128;
	private static final int RECIP_AO_PHONE_LENGTH = 30;
	private static final int RECIP_AO_FAX_LENGTH = 30;
	private static final int RECIPSCI_NAME_LENGTH = 256;
	private static final int RECIPSCI_TITLE_LENGTH = 256;

	@NotNull
	@Column(name = "SYMBOL", nullable = false)
	@Size(min = 1, max = SYMBOL_LENGTH)
	private String symbol;

	@NotNull
	@Column(name = "SMTA_DATE", nullable = false)
	@Size(min = 1, max = SMTA_DATE_LENGTH)
	private String smtaDate;

	@NotNull
	@Column(name = "SMTA_TYPE", nullable = false)
	@Size(min = 1, max = SMTA_TYPE_LENGTH)
	private String smtaType;

	@NotNull
	@Column(name = "LANGUAGE", nullable = false)
	@Size(min = 1, max = LANGUAGE_LENGTH)
	private String language;

	@NotNull
	@Column(name = "PROVIDER_TYPE", nullable = false)
	@Size(min = 1, max = PROVIDER_TYPE_LENGTH)
	private String providerType;

	@NotNull
	@Column(name = "PROVIDER_PID", nullable = false)
	@Size(min = 1, max = PROVIDER_PID_LENGTH)
	private String providerPid;

	@Column(name = "PROVIDER_NAME", nullable = true)
	@Size(max = PROVIDER_NAME_LENGTH)
	private String providerName;

	@NotNull
	@Lob
	@Column(name = "PROVIDER_ADDRESS", nullable = false)
	@Size(min = 1, max = PROVIDER_ADDRESS_LENGTH)
	private String providerAddress;

	@NotNull
	@Column(name = "PROVIDER_COUNTRY", nullable = false)
	@Size(min = 1, max = PROVIDER_COUNTRY_LENGTH)
	private String providerCountry;

	@NotNull
	@Column(name = "PROVIDER_EMAIL", nullable = false)
	@Size(min = 1, max = PROVIDER_EMAIL_LENGTH)
	private String providerEmail;

	@Column(name = "RECIPIENT_TYPE", nullable = true)
	@Size(max = RECIPIENT_TYPE_LENGTH)
	private String recipientType;

	@Column(name = "RECIPIENT_PID", nullable = true)
	@Size(max = RECIPIENT_PID_LENGTH)
	private String recipientPid;

	@Column(name = "RECIPIENT_NAME", nullable = true)
	@Size(max = RECIPIENT_NAME_LENGTH)
	private String recipientName;

	@Lob
	@Column(name = "RECIPIENT_ADDRESS", nullable = true)
	@Size(max = RECIPIENT_ADDRESS_LENGTH)
	private String recipientAddress;

	@NotNull
	@Column(name = "RECIPIENT_COUNTRY", nullable = false)
	@Size(min = 1, max = RECIPIENT_COUNTRY_LENGTH)
	private String recipientCountry;

	@NotNull
	@Column(name = "SHIPMENT_NAME", nullable = false)
	@Size(min = 1, max = SHIPMENT_NAME_LENGTH)
	private String shipmentName;

	@NotNull
	@Column(name = "DOCUMENT_LOCATION", nullable = false)
	@Size(min = 1, max = DOCUMENT_LOCATION_LENGTH)
	private String documentLocation;

	@Column(name = "DOCUMENT_RETRIEVAL_INFO", nullable = true)
	@Size(max = DOCUMENT_RETRIEVAL_INFO_LENGTH)
	private String documentRetrievalInfo;

	@Lob
	@Column(name = "PDF_URL", nullable = true)
	@Size(max = PDF_URL_LENGTH)
	private String pdfUrl;
	
//	@Column(name = "IRRI_AUTHORIZED_OFFICIAL_NAME", nullable = true)
//	@Size(max = IRRI_AUTHORIZED_OFFICIAL_NAME_LENGTH)
//	private String irriAuthorizedOfficialName;
//	
//	@Lob
//	@Column(name = "IRRI_AUTHORIZED_OFFICIAL_DETAILS", nullable = true)
//	@Size(max = IRRI_AUTHORIZED_OFFICIAL_DETAILS_LENGTH)
//	private String irriAuthorizedOfficialDetails;
//	
//	@Column(name = "RECIPIENT_AUTHORIZED_OFFICIAL_NAME", nullable = true)
//	@Size(max = RECIPIENT_AUTHORIZED_OFFICIAL_NAME_LENGTH)
//	private String recipientAuthorizedOfficialName;
//	
//	@Lob
//	@Column(name = "RECIPIENT_AUTHORIZED_OFFICIAL_DETAILS", nullable = true)
//	@Size(max = RECIPIENT_AUTHORIZED_OFFICIAL_DETAILS_LENGTH)
//	private String recipientAuthorizedOfficialDetails;
//
//	@Column(name = "RECIPIENT_INDIVIDUAL_NAME", nullable = true)
//	@Size(max = RECIPIENT_INDIVIDUAL_NAME_LENGTH)
//	private String recipientIndividualName;
//	
//	@Lob
//	@Column(name = "RECIPIENT_INDIVIDUAL_DETAILS", nullable = true)
//	@Size(max = RECIPIENT_INDIVIDUAL_DETAILS_LENGTH)
//	private String recipientIndividualDetails;
	
	@Column(name = "RECIPIENT_ORGANIZATION_NAME", nullable = true)
	@Size(max = RECIPIENT_ORGANIZATION_NAME_LENGTH)
	private String recipientOrganizationName;

//	@Lob
//	@Column(name = "RECIPIENT_ORGANIZATION_DETAILS", nullable = true)
//	@Size(max = RECIPIENT_ORGANIZATION_DETAILS_LENGTH)
//	private String recipientOrganizationDetails;
	
	@Column(name = "PROV_AO_NAME", nullable = true)
	@Size(max = PROV_AO_NAME_LENGTH)
	private String provAoName;
	
	@Column(name = "PROV_AO_TITLE", nullable = true)
	@Size(max = PROV_AO_TITLE_LENGTH)
	private String provAoTitle;
	
	@Column(name = "PROV_AO_EMAIL", nullable = true)
	@Size(max = PROV_AO_EMAIL_LENGTH)
	private String provAoEmail;
	
	@Column(name = "PROV_AO_PHONE", nullable = true)
	@Size(max = PROV_AO_PHONE_LENGTH)
	private String provAoPhone;
	
	@Column(name = "PROV_AO_FAX", nullable = true)
	@Size(max = PROV_AO_FAX_LENGTH)
	private String provAoFax;
	
	@Column(name = "SENDER_NAME", nullable = true)
	@Size(max = SENDER_NAME_LENGTH)
	private String senderName;
	
	@Column(name = "SENDER_TITLE", nullable = true)
	@Size(max = SENDER_TITLE_LENGTH)
	private String senderTitle;

	@Column(name = "RECIP_AO_NAME", nullable = true)
	@Size(max = RECIP_AO_NAME_LENGTH)
	private String recipAoName;
	
	@Column(name = "RECIP_AO_TITLE", nullable = true)
	@Size(max = RECIP_AO_TITLE_LENGTH)
	private String recipAoTitle;
	
	@Column(name = "RECIP_AO_EMAIL", nullable = true)
	@Size(max = RECIP_AO_EMAIL_LENGTH)
	private String recipAoEmail;
	
	@Column(name = "RECIP_AO_PHONE", nullable = true)
	@Size(max = RECIP_AO_PHONE_LENGTH)
	private String recipAoPhone;
	
	@Column(name = "RECIP_AO_FAX", nullable = true)
	@Size(max = RECIP_AO_FAX_LENGTH)
	private String recipAoFax;
	
	@Column(name = "RECIPSCI_NAME", nullable = true)
	@Size(max = RECIPSCI_NAME_LENGTH)
	private String recipSciName;
	
	@Column(name = "RECIPSCI_TITLE", nullable = true)
	@Size(max = RECIPSCI_TITLE_LENGTH)
	private String recipSciTitle;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "SMTA_MATERIAL", joinColumns = { @JoinColumn(name = "SMTA_REPORT_ID", referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "MATERIAL_ID", referencedColumnName = "ID") })
	private List<Material> materials = new ArrayList<Material>();

	@NotNull
	@Column(name = "REPORTED_TO_TREATY", nullable = false)
	private Boolean reportedToTreaty = Boolean.FALSE;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "REPORTED_DATE", nullable = true)
	private Date reportedDate;

	@NotNull
	@Column(name = "REPORT_ATTEMPTS", nullable = false)
	private Long reportAttempts = 0L;

	public SmtaReport() {
		super();
	}

	public String getSymbol() {
		return symbol;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
		if (symbol != null) {
			this.symbol = StringUtils.substring(symbol.trim(), 0, SYMBOL_LENGTH);
		}
	}

	public String getSmtaDate() {
		return StringUtils.defaultIfEmpty(smtaDate, "");
	}

	public void setSmtaDate(String smtaDate) {
		this.smtaDate = smtaDate;
		if (smtaDate != null) {
			this.smtaDate = StringUtils.substring(smtaDate.trim(), 0,
					SMTA_DATE_LENGTH);
		}
	}

	public String getSmtaType() {
		return StringUtils.defaultIfEmpty(smtaType, "");
	}

	public void setSmtaType(String smtaType) {
		this.smtaType = smtaType;
		if (smtaType != null) {
			this.smtaType = StringUtils.substring(smtaType.trim(), 0,
					SMTA_TYPE_LENGTH);
		}
	}

	public String getLanguage() {
		return StringUtils.defaultIfEmpty(language, "");
	}

	public void setLanguage(String language) {
		this.language = language;
		if (language != null) {
			this.language = StringUtils.substring(language.trim(), 0,
					LANGUAGE_LENGTH);
		}
	}

	public String getProviderType() {
		return StringUtils.defaultIfEmpty(providerType, "");
	}

	public void setProviderType(String providerType) {
		this.providerType = providerType;
		if (providerType != null) {
			this.providerType = StringUtils.substring(providerType.trim(), 0,
					PROVIDER_TYPE_LENGTH);
		}
	}

	public String getProviderPid() {
		return StringUtils.defaultIfEmpty(providerPid, "");
	}

	public void setProviderPid(String providerPid) {
		this.providerPid = providerPid;
		if (providerPid != null) {
			this.providerPid = StringUtils.substring(providerPid.trim(), 0,
					PROVIDER_PID_LENGTH);
		}
	}

	public String getProviderName() {
		return StringUtils.defaultIfEmpty(providerName, "");
	}

	public void setProviderName(String providerName) {
		this.providerName = providerName;
		if (providerName != null) {
			this.providerName = StringUtils.substring(providerName.trim(), 0,
					PROVIDER_NAME_LENGTH);
		}
	}

	public String getProviderAddress() {
		return StringUtils.defaultIfEmpty(providerAddress, "");
	}

	public void setProviderAddress(String providerAddress) {
		this.providerAddress = providerAddress;
		if (providerAddress != null) {
			this.providerAddress = StringUtils.substring(providerAddress.trim(), 0,
					PROVIDER_ADDRESS_LENGTH);
		}
	}

	public String getProviderCountry() {
		return StringUtils.defaultIfEmpty(providerCountry, "");
	}

	public void setProviderCountry(String providerCountry) {
		this.providerCountry = providerCountry;
		if (providerCountry != null) {
			this.providerCountry = StringUtils.substring(providerCountry.trim(), 0,
					PROVIDER_COUNTRY_LENGTH);
		}
	}

	public String getProviderEmail() {
		return StringUtils.defaultIfEmpty(providerEmail, "");
	}

	public void setProviderEmail(String providerEmail) {
		this.providerEmail = providerEmail;
		if (providerEmail != null) {
			this.providerEmail = StringUtils.substring(providerEmail.trim(), 0,
					PROVIDER_EMAIL_LENGTH);
		}
	}

	public String getRecipientType() {
		return StringUtils.defaultIfEmpty(recipientType, "");
	}

	public void setRecipientType(String recipientType) {
		this.recipientType = recipientType;
		if (recipientType != null) {
			this.recipientType = StringUtils.substring(recipientType.trim(), 0,
					RECIPIENT_TYPE_LENGTH);
		}
	}

	public String getRecipientPid() {
		return StringUtils.defaultIfEmpty(recipientPid, "");
	}

	public void setRecipientPid(String recipientPid) {
		this.recipientPid = recipientPid;
		if (recipientPid != null) {
			this.recipientPid = StringUtils.substring(recipientPid.trim(), 0,
					RECIPIENT_PID_LENGTH);
		}
	}

	public String getRecipientName() {
		return StringUtils.defaultIfEmpty(recipientName, "");
	}

	public void setRecipientName(String recipientName) {
		this.recipientName = recipientName;
		if (recipientName != null) {
			this.recipientName = StringUtils.substring(recipientName.trim(), 0,
					RECIPIENT_NAME_LENGTH);
		}
	}

	public String getRecipientAddress() {
		return StringUtils.defaultIfEmpty(recipientAddress, "");
	}

	public void setRecipientAddress(String recipientAddress) {
		this.recipientAddress = recipientAddress;
		if (recipientAddress != null) {
			this.recipientAddress = StringUtils.substring(recipientAddress.trim(),
					0, RECIPIENT_ADDRESS_LENGTH);
		}
	}

	public String getRecipientCountry() {
		return StringUtils.defaultIfEmpty(recipientCountry, "");
	}

	public void setRecipientCountry(String recipientCountry) {
		this.recipientCountry = recipientCountry;
		if (recipientCountry != null) {
			this.recipientCountry = StringUtils.substring(recipientCountry.trim(),
					0, RECIPIENT_COUNTRY_LENGTH);
		}
	}

	public String getShipmentName() {
		return StringUtils.defaultIfEmpty(shipmentName, "");
	}

	public void setShipmentName(String shipmentName) {
		this.shipmentName = shipmentName;
		if (shipmentName != null) {
			this.shipmentName = StringUtils.substring(shipmentName.trim(), 0,
					SHIPMENT_NAME_LENGTH);
		}
	}

	public String getDocumentLocation() {
		return StringUtils.defaultIfEmpty(documentLocation, "");
	}

	public void setDocumentLocation(String documentLocation) {
		this.documentLocation = documentLocation;
		if (documentLocation != null) {
			this.documentLocation = StringUtils.substring(documentLocation.trim(),
					0, DOCUMENT_LOCATION_LENGTH);
		}
	}

	public String getDocumentRetrievalInfo() {
		return StringUtils.defaultIfEmpty(documentRetrievalInfo, "");
	}

	public void setDocumentRetrievalInfo(String documentRetrievalInfo) {
		this.documentRetrievalInfo = documentRetrievalInfo;
		if (documentRetrievalInfo != null) {
			this.documentRetrievalInfo = StringUtils
					.substring(documentRetrievalInfo.trim(), 0,
							DOCUMENT_RETRIEVAL_INFO_LENGTH);
		}
	}

	public String getPdfUrl() {
		return StringUtils.defaultIfEmpty(pdfUrl, "");
	}

	public void setPdfUrl(String pdfUrl) {
		this.pdfUrl = pdfUrl;
		if (pdfUrl != null) {
			this.pdfUrl = StringUtils.substring(pdfUrl.trim(), 0, PDF_URL_LENGTH);
		}
	}

//	public String getIrriAuthorizedOfficialName() {
//		return StringUtils.defaultIfEmpty(irriAuthorizedOfficialName, "");
//	}
//
//	public void setIrriAuthorizedOfficialName(String irriAuthorizedOfficialName) {
//		this.irriAuthorizedOfficialName = irriAuthorizedOfficialName;
//		if (irriAuthorizedOfficialName != null) {
//			this.irriAuthorizedOfficialName = StringUtils.substring(
//					irriAuthorizedOfficialName.trim(), 0,
//					IRRI_AUTHORIZED_OFFICIAL_NAME_LENGTH);
//		}
//	}
//
//	public String getIrriAuthorizedOfficialDetails() {
//		return StringUtils.defaultIfEmpty(irriAuthorizedOfficialDetails, "");
//	}
//
//	public void setIrriAuthorizedOfficialDetails(
//			String irriAuthorizedOfficialDetails) {
//		this.irriAuthorizedOfficialDetails = irriAuthorizedOfficialDetails;
//		if (irriAuthorizedOfficialDetails != null) {
//			this.irriAuthorizedOfficialDetails = StringUtils.substring(
//					irriAuthorizedOfficialDetails.trim(), 0,
//					IRRI_AUTHORIZED_OFFICIAL_DETAILS_LENGTH);
//		}
//	}
//
//	public String getRecipientAuthorizedOfficialName() {
//		return StringUtils.defaultIfEmpty(recipientAuthorizedOfficialName, "");
//	}
//
//	public void setRecipientAuthorizedOfficialName(String recipientAuthorizedOfficialName) {
//		this.recipientAuthorizedOfficialName = recipientAuthorizedOfficialName;
//		if (recipientAuthorizedOfficialName != null) {
//			this.recipientAuthorizedOfficialName = StringUtils.substring(
//					recipientAuthorizedOfficialName.trim(), 0,
//					RECIPIENT_AUTHORIZED_OFFICIAL_NAME_LENGTH);
//		}
//	}
//
//	public String getRecipientAuthorizedOfficialDetails() {
//		return StringUtils.defaultIfEmpty(recipientAuthorizedOfficialDetails, "");
//	}
//
//	public void setRecipientAuthorizedOfficialDetails(String recipientAuthorizedOfficialDetails) {
//		this.recipientAuthorizedOfficialDetails = recipientAuthorizedOfficialDetails;
//		if (recipientAuthorizedOfficialDetails != null) {
//			this.recipientAuthorizedOfficialDetails = StringUtils.substring(
//					recipientAuthorizedOfficialDetails.trim(), 0,
//					RECIPIENT_AUTHORIZED_OFFICIAL_DETAILS_LENGTH);
//		}
//	}
//
//	public String getRecipientIndividualName() {
//		return StringUtils.defaultIfEmpty(recipientIndividualName, "");
//	}
//
//	public void setRecipientIndividualName(String recipientIndividualName) {
//		this.recipientIndividualName = recipientIndividualName;
//		if (recipientIndividualName != null) {
//			this.recipientIndividualName = StringUtils.substring(
//					recipientIndividualName.trim(), 0, RECIPIENT_NAME_LENGTH);
//		}
//	}
//
//	public String getRecipientIndividualDetails() {
//		return StringUtils.defaultIfEmpty(recipientIndividualDetails, "");
//	}
//
//	public void setRecipientIndividualDetails(String recipientIndividualDetails) {
//		this.recipientIndividualDetails = recipientIndividualDetails;
//		if (recipientIndividualDetails != null) {
//			this.recipientIndividualDetails = StringUtils.substring(
//					recipientIndividualDetails.trim(), 0,
//					RECIPIENT_INDIVIDUAL_DETAILS_LENGTH);
//		}
//	}

	public String getRecipientOrganizationName() {
		return StringUtils.defaultIfEmpty(recipientOrganizationName, "");
	}

	public void setRecipientOrganizationName(String recipientOrganizationName) {
		this.recipientOrganizationName = recipientOrganizationName;
		if (recipientOrganizationName != null) {
			this.recipientOrganizationName = StringUtils.substring(
					recipientOrganizationName.trim(), 0,
					RECIPIENT_ORGANIZATION_NAME_LENGTH);
		}
	}

//	public String getRecipientOrganizationDetails() {
//		return StringUtils.defaultIfEmpty(recipientOrganizationDetails, "");
//	}
//
//	public void setRecipientOrganizationDetails(String recipientOrganizationDetails) {
//		this.recipientOrganizationDetails = recipientOrganizationDetails;
//		if (recipientOrganizationDetails != null) {
//			this.recipientOrganizationDetails = StringUtils.substring(
//					recipientOrganizationDetails.trim(), 0,
//					RECIPIENT_ORGANIZATION_DETAILS_LENGTH);
//		}
//	}

	public String getProvAoName() {
		return StringUtils.defaultIfEmpty(provAoName, "");
	}

	public void setProvAoName(String provAoName) {
		this.provAoName = provAoName;
		if (provAoName != null) {
			this.provAoName = StringUtils.substring(
					provAoName.trim(), 0,
					PROV_AO_NAME_LENGTH);
		}
	}

	public String getProvAoTitle() {
		return StringUtils.defaultIfEmpty(provAoTitle, "");
	}

	public void setProvAoTitle(String provAoTitle) {
		this.provAoTitle = provAoTitle;
		if (provAoTitle != null) {
			this.provAoTitle = StringUtils.substring(
					provAoTitle.trim(), 0,
					PROV_AO_TITLE_LENGTH);
		}
	}

	public String getProvAoEmail() {
		return StringUtils.defaultIfEmpty(provAoEmail, "");
	}

	public void setProvAoEmail(String provAoEmail) {
		this.provAoEmail = provAoEmail;
		if (provAoEmail != null) {
			this.provAoEmail = StringUtils.substring(
					provAoEmail.trim(), 0,
					PROV_AO_EMAIL_LENGTH);
		}
	}

	public String getProvAoPhone() {
		return StringUtils.defaultIfEmpty(provAoPhone, "");
	}

	public void setProvAoPhone(String provAoPhone) {
		this.provAoPhone = provAoPhone;
		if (provAoPhone != null) {
			this.provAoPhone = StringUtils.substring(
					provAoPhone.trim(), 0,
					PROV_AO_PHONE_LENGTH);
		}
	}

	public String getProvAoFax() {
		return StringUtils.defaultIfEmpty(provAoFax, "");
	}

	public void setProvAoFax(String provAoFax) {
		this.provAoFax = provAoFax;
		if (provAoFax != null) {
			this.provAoFax = StringUtils.substring(
					provAoFax.trim(), 0,
					PROV_AO_FAX_LENGTH);
		}
	}

	public String getSenderName() {
		return StringUtils.defaultIfEmpty(senderName, "");
	}

	public void setSenderName(String senderName) {
		this.senderName = senderName;
		if (senderName != null) {
			this.senderName = StringUtils.substring(
					senderName.trim(), 0,
					SENDER_NAME_LENGTH);
		}
	}

	public String getSenderTitle() {
		return StringUtils.defaultIfEmpty(senderTitle, "");
	}

	public void setSenderTitle(String senderTitle) {
		this.senderTitle = senderTitle;
		if (senderTitle != null) {
			this.senderTitle = StringUtils.substring(
					senderTitle.trim(), 0,
					SENDER_TITLE_LENGTH);
		}
	}

	public String getRecipAoName() {
		return StringUtils.defaultIfEmpty(recipAoName, "");
	}

	public void setRecipAoName(String recipAoName) {
		this.recipAoName = recipAoName;
		if (recipAoName != null) {
			this.recipAoName = StringUtils.substring(
					recipAoName.trim(), 0,
					RECIP_AO_NAME_LENGTH);
		}
	}

	public String getRecipAoTitle() {
		return StringUtils.defaultIfEmpty(recipAoTitle, "");
	}

	public void setRecipAoTitle(String recipAoTitle) {
		this.recipAoTitle = recipAoTitle;
		if (recipAoTitle != null) {
			this.recipAoTitle = StringUtils.substring(
					recipAoTitle.trim(), 0,
					RECIP_AO_TITLE_LENGTH);
		}
	}

	public String getRecipAoEmail() {
		return StringUtils.defaultIfEmpty(recipAoEmail, "");
	}

	public void setRecipAoEmail(String recipAoEmail) {
		this.recipAoEmail = recipAoEmail;
		if (recipAoEmail != null) {
			this.recipAoEmail = StringUtils.substring(
					recipAoEmail.trim(), 0,
					RECIP_AO_EMAIL_LENGTH);
		}
	}

	public String getRecipAoPhone() {
		return StringUtils.defaultIfEmpty(recipAoPhone, "");
	}

	public void setRecipAoPhone(String recipAoPhone) {
		this.recipAoPhone = recipAoPhone;
		if (recipAoPhone != null) {
			this.recipAoPhone = StringUtils.substring(
					recipAoPhone.trim(), 0,
					RECIP_AO_PHONE_LENGTH);
		}
	}

	public String getRecipAoFax() {
		return StringUtils.defaultIfEmpty(recipAoFax, "");
	}

	public void setRecipAoFax(String recipAoFax) {
		this.recipAoFax = recipAoFax;
		if (recipAoFax != null) {
			this.recipAoFax = StringUtils.substring(
					recipAoFax.trim(), 0,
					RECIP_AO_FAX_LENGTH);
		}
	}

	public String getRecipSciName() {
		return StringUtils.defaultIfEmpty(recipSciName, "");
	}

	public void setRecipSciName(String recipSciName) {
		this.recipSciName = recipSciName;
		if (recipSciName != null) {
			this.recipSciName = StringUtils.substring(
					recipSciName.trim(), 0,
					RECIPSCI_NAME_LENGTH);
		}
	}

	public String getRecipSciTitle() {
		return StringUtils.defaultIfEmpty(recipSciTitle, "");
	}

	public void setRecipSciTitle(String recipSciTitle) {
		this.recipSciTitle = recipSciTitle;
		if (recipSciTitle != null) {
			this.recipSciTitle = StringUtils.substring(
					recipSciTitle.trim(), 0,
					RECIPSCI_TITLE_LENGTH);
		}
	}

	public List<Material> getMaterials() {
		return materials;
	}

	public void setMaterials(List<Material> materials) {
		this.materials = materials;
	}

	public Boolean getReportedToTreaty() {
		return reportedToTreaty;
	}

	public void setReportedToTreaty(Boolean reportedToTreaty) {
		if (reportedToTreaty == null) {
			this.reportedToTreaty = Boolean.FALSE;
		} else {
			this.reportedToTreaty = reportedToTreaty;
		}
	}

	public Date getReportedDate() {
		return reportedDate;
	}

	public void setReportedDate(Date reportedDate) {
		this.reportedDate = reportedDate;
	}

	public Long getReportAttempts() {
		return reportAttempts;
	}

	public void setReportAttempts(Long reportAttempts) {
		if (reportAttempts > 0) {
			this.reportAttempts = 0L;
		} else {
			this.reportAttempts = reportAttempts;
		}
	}

	@Override
	public int compareTo(SmtaReport o) {
		if (o != null) {
			return this.getId().compareTo(o.getId());
		}
		return 0;
	}

	@Override
	public String toString() {
		return "SmtaReport [symbol=" + symbol + ", smtaDate=" + smtaDate
				+ ", smtaType=" + smtaType + ", language=" + language
				+ ", providerType=" + providerType + ", providerPid="
				+ providerPid + ", providerName=" + providerName
				+ ", providerAddress=" + providerAddress + ", providerCountry="
				+ providerCountry + ", providerEmail=" + providerEmail
				+ ", recipientType=" + recipientType + ", recipientPid="
				+ recipientPid + ", recipientName=" + recipientName
				+ ", recipientAddress=" + recipientAddress
				+ ", recipientCountry=" + recipientCountry + ", shipmentName="
				+ shipmentName + ", documentLocation=" + documentLocation
				+ ", documentRetrievalInfo=" + documentRetrievalInfo
				+ ", pdfUrl=" + pdfUrl + ", provAoName=" + provAoName
				+ ", provAoTitle=" + provAoTitle + ", provAoEmail="
				+ provAoEmail + ", provAoPhone=" + provAoPhone + ", provAoFax="
				+ provAoFax + ", senderName=" + senderName + ", senderTitle="
				+ senderTitle + ", recipAoName=" + recipAoName
				+ ", recipAoTitle=" + recipAoTitle + ", recipAoEmail="
				+ recipAoEmail + ", recipAoPhone=" + recipAoPhone
				+ ", recipAoFax=" + recipAoFax + ", recipSciName="
				+ recipSciName + ", recipSciTitle=" + recipSciTitle
				+ ", materials=" + materials + ", reportedToTreaty="
				+ reportedToTreaty + ", reportedDate=" + reportedDate
				+ ", reportAttempts=" + reportAttempts + "]";
	}

}
